package com.qsmx.store.app.main.mem;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ListView;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.main.mem.adapter.coin.MemCardPropertyCoinsTableListAdapter;
import com.qsmx.store.app.main.mem.adapter.ticket.MemCardPropertyTicketTableListAdapter;
import com.qsmx.store.app.main.mem.adapter.ticket.TicketPanelListLayout;
import com.qsmx.store.app.main.mem.entity.MemTicketEntity;
import com.qsmx.store.app.widget.PanelListLayout;
import com.qsmx.store.core.delegates.AtmosDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MemCardPropertySearchTicketDelegate extends AtmosDelegate {

    private MemCardPropertyTicketTableListAdapter mAdapter;
    private List<String> rowDataList = new ArrayList<>();
    private List<Integer> itemWidthList = new ArrayList<>();
    private List<MemTicketEntity> contentList = new ArrayList<>();

    @BindView(R2.id.pl_root)
    TicketPanelListLayout plRoot;
    @BindView(R2.id.lv_xls)
    ListView lvXls;

    @Override
    public Object setLayout() {
        return R.layout.delegate_mem_card_property_ticket_search_info;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        initRowDataList();
        initContentDataList();
        initItemWidthList();
        initAdapter();
        plRoot.setAdapter(mAdapter);
        plRoot.getAdapter().setContentData(contentList);

    }

    private void initAdapter() {
        mAdapter = new MemCardPropertyTicketTableListAdapter(getContext(), plRoot, lvXls, R.layout.adapter_mem_card_property_search_ticket);
        mAdapter.setTitleWidth(0);
        mAdapter.setTitleHeight(40);
        mAdapter.setRowColor("#04b098");
        mAdapter.setSwipeRefreshEnabled(false);
        mAdapter.setOnRefreshListener(new CustomRefreshListener());// optional
        mAdapter.setRowDataList(rowDataList);// must have
        mAdapter.setItemWidthList(itemWidthList);// must have
        mAdapter.setItemHeight(40);// optional, dp
    }

    /**
     * 生成一份横向表头的内容
     *
     * @return List<String>
     */
    private void initRowDataList() {
        rowDataList.add(getString(R.string.mem_card_property_search_ic));
        rowDataList.add(getString(R.string.mem_card_property_search_account));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_time));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_machine_num));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_machine_name));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_mem_name));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_num));
        rowDataList.add(getString(R.string.mem_card_property_search_times));
        rowDataList.add(getString(R.string.mem_card_property_search_do_person));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_shift));
        rowDataList.add(getString(R.string.mem_card_property_search_remark));
        rowDataList.add(getString(R.string.mem_card_property_search_save_ticket_order));
    }

    private void initItemWidthList() {
        itemWidthList.add(150);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(150);
        itemWidthList.add(200);
    }

    private void initContentDataList() {

        contentList = new ArrayList<>();
        for (int i = 0; i <= 20; i++) {
            MemTicketEntity tickets = new MemTicketEntity();
            tickets.setTest(i + "");
            contentList.add(tickets);
        }

    }


    public class CustomRefreshListener implements SwipeRefreshLayout.OnRefreshListener {
        @Override
        public void onRefresh() {
            // don`t forget to call this
            mAdapter.getSwipeRefreshLayout().setRefreshing(false);
        }
    }

}
